home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / mint / netlib / lib / sendto.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-27  |  1.4 KB  |  77 lines

  1. /*
  2.  *    sendto() emulation for MiNT-Net, (w) '93, kay roemer
  3.  */
  4.  
  5. #include "socklib.h"
  6. #ifdef KERNEL
  7. #undef UNX2DOS
  8. #include "kerbind.h"
  9. #else
  10. #include <mintbind.h>
  11. #include <errno.h>
  12. #endif
  13. #include "sys/socket.h"
  14. #include "mintsock.h"
  15.  
  16. #ifdef UNX2DOS
  17. #include <string.h>
  18. #include "sys/un.h"
  19. #define UN_OFFSET    ((short)((struct sockaddr_un *)0)->sun_path)
  20. #endif
  21.  
  22. #ifndef KERNEL
  23. extern int errno;
  24. #endif
  25.  
  26. int
  27. sendto (fd, buf, buflen, flags, addr, addrlen)
  28.     int fd;
  29.     void *buf;
  30.     _SIZE_T buflen;
  31.     int flags;
  32.     struct sockaddr *addr;
  33.     _SIZE_T addrlen;
  34. {
  35.     struct sendto_cmd cmd;
  36.     int r;
  37. #ifdef UNX2DOS
  38.     struct sockaddr_un un;
  39.     extern int _unx2dos (const char *, char *);
  40.  
  41.     if (addr && addr->sa_family == AF_UNIX) {
  42.         struct sockaddr_un *unp = (struct sockaddr_un *)addr;
  43.  
  44.         if (addrlen <= UN_OFFSET || addrlen > sizeof (un)) {
  45.             errno = EINVAL;
  46.             return -1;
  47.         }
  48.  
  49.         un.sun_family = AF_UNIX;
  50.         _unx2dos (unp->sun_path, un.sun_path);
  51.         un.sun_path[sizeof (un.sun_path) - 1] = '\0';
  52.         cmd.addr =    (struct sockaddr *)&un;
  53.         cmd.addrlen =    UN_OFFSET + strlen (un.sun_path);
  54.     } else {
  55. #endif
  56.         cmd.addr =    addr;
  57.         cmd.addrlen =     (short)addrlen;
  58. #ifdef UNX2DOS
  59.     }
  60. #endif
  61.     cmd.cmd =    SENDTO_CMD;
  62.     cmd.buf =    buf;
  63.     cmd.buflen =    buflen;
  64.     cmd.flags =    flags;
  65.  
  66. #ifdef KERNEL
  67.     r = f_cntl (fd, (long)&cmd, SOCKETCALL);
  68. #else
  69.     r = Fcntl (fd, (long)&cmd, SOCKETCALL);
  70.     if (r < 0) {
  71.         errno = -r;
  72.         return -1;
  73.     }
  74. #endif
  75.     return r;
  76. }
  77.